from django.db import models


class Book(models.Model):
    title = models.CharField("书名", null=False, unique=True, max_length=20)
    pub = models.CharField("出版社" , null=False, max_length=20)
    price = models.DecimalField("价钱", max_digits=6, decimal_places=2)
    market_price = models.DecimalField("零售价", max_digits=6, decimal_places=2)

    class Meta:
        db_table = "Book"

    def __str__(self):
        return f"{self.id}-{self.title}-{self.pub}"


class Author(models.Model):
    name = models.CharField("姓名", null=False, max_length=20)
    age = models.IntegerField("年龄", null=False, default=1)
    email = models.EmailField("邮箱", null=True)

    class Meta:
        db_table = "Author"

    def __str__(self):
        return f"{self.id}-{self.name}"
